package org.dromara.hrp.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.dromara.hrp.service.impl.HrpPartnerServiceImpl;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.PageData;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hrp.domain.HrpPartner;

/**
 * 联系人合作伙伴
 *
 * @author wenrui Su
 * @date 2024-05-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hrp/partner")
public class HrpPartnerController extends BaseService {

  private final HrpPartnerServiceImpl hrpPartnerService;

  /**
   * 查询联系人合作伙伴列表
   */
  @SaCheckPermission("hrp:partner:list")
  @GetMapping("/list")
  public PageData list(HrpPartner bo, PageQuery pageQuery) {
    return this.resPage(hrpPartnerService.queryPageList(bo, pageQuery));
  }

  /**
   * 导出联系人合作伙伴列表
   */
  @SaCheckPermission("hrp:partner:export")
  @Log(title = "联系人合作伙伴", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HrpPartner bo, HttpServletResponse response) {
    List<HrpPartner> list = hrpPartnerService.queryList(bo);
    ExcelUtil.exportExcel(list, "联系人合作伙伴", HrpPartner. class,response);
  }

  /**
   * 获取联系人合作伙伴详细信息
   *
   * @param id 主键
   */
  @SaCheckPermission("hrp:partner:query")
  @GetMapping("/{id}")
  public PageData getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
    return this.resData(hrpPartnerService.queryById(id));
  }

  /**
   * 新增联系人合作伙伴
   */
  @SaCheckPermission("hrp:partner:add")
  @Log(title = "联系人合作伙伴", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public PageData add(@Validated(AddGroup.class) @RequestBody HrpPartner bo) {
    return this.resData(hrpPartnerService.insertByBo(bo));
  }

  /**
   * 修改联系人合作伙伴
   */
  @SaCheckPermission("hrp:partner:edit")
  @Log(title = "联系人合作伙伴", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public PageData edit(@Validated(EditGroup.class) @RequestBody HrpPartner bo) {
    return this.resData(hrpPartnerService.updateByBo(bo));
  }

  /**
   * 删除联系人合作伙伴
   *
   * @param ids 主键串
   */
  @SaCheckPermission("hrp:partner:remove")
  @Log(title = "联系人合作伙伴", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public PageData remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
    return this.resData(hrpPartnerService.deleteWithValidByIds(List.of(ids), true));
  }
}
